package ms07.ticketPro.sms;

import ms07.ticketPro.DebugLog;
import ms07.ticketPro.MyApplication;
import ms07.ticketPro.Ticket;

public abstract class Parser{
	private static Parser instance;
	public static Parser getInstance(){
		//TODO logic to create right parser in terms of which country
		
		if(instance==null){
			instance = new ParserAustria();
		}
		
		return instance;
	}
	
	protected String text;
	protected Ticket ticket;
	
	public void setText(String text){
		DebugLog.getInstance().log("Parser called...");
		this.text = text;
	}
	
	public abstract void parseText() throws Exception;

	public boolean checkNumber(String number) {
		number = number.replace("+43", "0");
		
		DebugLog.getInstance().log("Check number: "+number);
		
		for(String provider: MyApplication.getInstance().getSMSProviders()){
			if(provider.matches(number)){
				return true;
			}
		}
		
		return false;
	}
	
	public final Ticket getTicket(){
		return this.ticket;
	}
}
